import requests


class IhrmApi:
    # 封装登录接口
    @classmethod
    def login_ihrm_api(cls, login_body) :
        login_url = "http://ihrm2-test.itheima.net/api/sys/login"
        login_header = {"Content-Type": "application/json"}
        login_resp = requests.post(url=login_url, headers=login_header, json=login_body)
        return login_resp

    # 封装添加员工接口
    @classmethod
    def add_emp_api(cls, token, add_emp_body):
        add_emp_url = "http://ihrm2-test.itheima.net/api/sys/user"
        add_emp_header = {"Content-Type": "application/json", "Authorization": token}
        add_emp_resp = requests.post(url=add_emp_url, headers=add_emp_header, json=add_emp_body)
        return add_emp_resp

    # 封装查询员工接口
    @classmethod
    def query_emp(cls, emp_id, token):
        query_emp_url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        query_emp_header = {"Authorization": token}
        query_emp_resp = requests.get(url=query_emp_url, headers=query_emp_header)
        return query_emp_resp

    # 封装修改员工接口
    @classmethod
    def modify_emp_api(cls, emp_id, token, modify_emp_body):
        modify_emp_url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        modify_emp_header = {"Content-Type": "application/json", "Authorization": token}
        modify_emp_resp = requests.put(url=modify_emp_url, headers=modify_emp_header, json=modify_emp_body)
        return modify_emp_resp

    # 封装删除员工接口
    @classmethod
    def del_emp_api(cls, emp_id, token):
        del_emp_url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        del_emp_header = {"Authorization": token}
        del_emp_resp = requests.delete(url=del_emp_url, headers=del_emp_header)
        return del_emp_resp


if __name__ == '__main__':#调用检查
    token = "b2123873-bbca-4154-9280-5b917d2d4c20"
    body = {"username": "小猪佩奇",
            "mobile": "15934002145",
            "workNumber": "22"}
    print("添加的结果=",IhrmApi.add_emp_api(token, body).json())

    emp_id="1573881156233867264"
    modify_emp_body={"username": "齐天大圣"}

    print("查询的结果=",IhrmApi.query_emp(emp_id, token).json())

    print("修改的结果=",IhrmApi.modify_emp_api(emp_id, token, modify_emp_body).json())